package com.chang.bootplus.controller;


import com.chang.bootplus.base.annotation.PublicVisit;
import com.chang.bootplus.base.utils.ApiResponse;
import com.chang.bootplus.po.*;
import com.chang.bootplus.service.MatrixOrderService;
import com.chang.bootplus.vo.OrderVO;
import com.chang.bootplus.vo.ProductUnitVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/matrix-order")
@Api(tags = {"订单信息"})
@CrossOrigin(origins = "*")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MatrixOrderController {

    final MatrixOrderService matrixOrderService;

    // 查找订单信息
    @PostMapping("list")
    @ApiOperation(httpMethod = "POST", value = "查询所有/某一用户 的订单，或按照订单编号/订单id 进行查询")
    public ApiResponse<OrderVO> listOrder(@RequestBody OrderSelPO po){
        return matrixOrderService.listOrder(po);
    }

    // 添加订单信息
    @PostMapping("add")
    @ApiOperation(httpMethod = "POST", value = "添加订单信息,用户点击购买生成订单")
    public ApiResponse<Void> addOrder(@RequestBody OrderPO po){
        return matrixOrderService.addOrder(po);
    }

    // 修改订单信息 （包含修改商品状态 （如缺货等））
    @PostMapping("update")
    @ApiOperation(httpMethod = "POST", value = "修改订单信息")
    public ApiResponse<Void> updateOrder(@RequestBody OrderListPO po){
        return matrixOrderService.updateOrder(po);
    }

    // 删除订单信息
    @PostMapping("delete")
    @ApiOperation(httpMethod = "POST", value = "删除订单信息")
    public ApiResponse<Void> deleteOrder(@RequestBody OrderIdPO po){
        return matrixOrderService.deleteOrder(po);
    }

    // 商家点击发货
    @PostMapping("deliver")
    @ApiOperation(httpMethod = "POST", value = "商家点击发货")
    public ApiResponse<Void> deliverOrder(@RequestBody OrderIdPO po){
        return matrixOrderService.deliverOrder(po);
    }

    // 用户点击付款
    @PostMapping("pay")
    @ApiOperation(httpMethod = "POST", value = "用户点击付款")
    public ApiResponse<Void> payOrder(@RequestBody OrderIdPO po){
        return matrixOrderService.payOrder(po);
    }

    // 用户点击收货，记录收货时间
    @PostMapping("receive")
    @ApiOperation(httpMethod = "POST", value = "用户点击收货")
    public ApiResponse<Void> receiveOrder(@RequestBody OrderIdPO po){
        return matrixOrderService.receiveOrder(po);
    }

}

